/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sct_beans;

import com.sun.istack.logging.Logger;
import java.util.logging.Level;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import entities.TestItem;
import javax.ejb.EJB;

/**
 *
 * @author ryuju
 */
@MessageDriven(mappedName = "jms/TestUnitMsgQueue", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class TestMsgHandler implements MessageListener {
    @EJB
    private SourceCodeTest sourceCodeTest;
    
    public TestMsgHandler() {
    }
    
    @Override
    public void onMessage(Message message) {
        ObjectMessage om = (ObjectMessage) message;
        if (null != om) {
            try {
                Object ret = om.getObject();
                if(null != ret)
                {
                    TestItem tu = (TestItem)ret;
                    // do source code test
                    sourceCodeTest.runTest(tu);
                }
            // process test unit
            } catch (JMSException ex) {
                java.util.logging.Logger.getLogger(TestMsgHandler.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        else
        {
            java.util.logging.Logger.getLogger(TestMsgHandler.class.getName()).log(Level.WARNING, null, "Message is null");
        }
    }
}
